import urllib
from urllib import request
# import urllib.request
def main() -> object:
    baseurl = "https://movie.douban.com/top250?start="
    datalist = getData(baseurl)
    savepath = ".\\豆瓣电影top250.xls"
    # saveDate(savepath)
    askURL("https://movie.douban.com/top250?start=0")

def getData(baseurl):
    datalist =[]
    return datalist

def askURL(url):

    head = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
    }
    req =request.Request(url,headers=head)
    html = ""
    try:
        response = request.urlopen(req)
        html = response.read().decode("utf-8")
        print(html)
    except urllib.error.URLError as e:
        if hasattr(e, "code"):
            print(e.code)
        if hasattr(e, "reason"):
            print(e.reason)
    # return html


def saveDate(savepath):
    print("save...")


if __name__ == "__main__":
    main()

